<?php
if(!defined('PATH')) exit();

class Model_StoreRecordList extends SimpleO {

	private $data = array();
	private $index = -1;

	public function __construct() {
		parent::__construct();
	}

	public function load($_account) {
		$this->data = array();
		$this->index = -1;
		$temp = $this->db->query('SELECT * FROM `__archez_store_record` WHERE `__archez_store_record`.`fromacc` = '.$this->db->quote($_account))->fetchAll();
		foreach ($temp as $key => $value) {
			$this->data[$key] = new Model_StoreRecord();
			foreach ($value as $inner_key => $inner_value) {
				$this->data[$key]->$inner_key = $inner_value;
			}
		}
		if ($this->count() > 0)
			return true;
		return false;
	}

	public function loadReceived($_guid, $_fromacc, $_type, $_join = false) {
		static $i;
		if (!$_join) {
			$i = 0;
			$this->index = -1;
			$this->data = array();
		}
		$temp = $this->db->query('SELECT * FROM `__archez_store_record` WHERE `__archez_store_record`.`toguid` = '.$this->db->quote($_guid).' AND `__archez_store_record`.`type` = '.$this->db->quote($_type).' AND `__archez_store_record`.`fromacc` != '.$this->db->quote($_fromacc))->fetchAll();
		foreach ($temp as $key => $value) {
			$this->data[$i] = new Model_StoreRecord();
			foreach ($value as $inner_key => $inner_value) {
				$this->data[$i]->$inner_key = $inner_value;
			}
			$i++;
		}
		if ($this->count() > 0)
			return true;
		return false;
	}

	public function next() {
		$this->index++;
		if ($this->index >= count($this->data))
			return false;
		return $this->data[$this->index];
	}

	public function count() {
		return count($this->data);
	}

	public function countAll() {
		$count = $this->db->query('SELECT COUNT(*) as `n`  FROM `__archez_store_record`;')->fetch();
		return $count['n'];
	}

	public function isLoaded() {
		if ($this->count() > 0) {
			return true;
		}
		return false;
	}
}

?>